unit GL_COA;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TGLCOA=class(TUniEngine)
  private
    FCOAID    : string;
    FCOACODE  : string;
    FCOANAME  : string;
    FCOADESC  : string;                
    FENABLED  : Extended;
    FCREATEDATE: string;
    FCREATEUSER: string;
    FLATESTOPDATE: string;
    FLATESTOPUSER: string;
    FLASTVER  : string;
    FSETYEAR  : Extended;
    FRGCODE   : string;
    FCCIDSTABLE: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property COAID    : string read FCOAID     write FCOAID;
    property COACODE  : string read FCOACODE   write FCOACODE;
    property COANAME  : string read FCOANAME   write FCOANAME;
    property COADESC  : string read FCOADESC   write FCOADESC;
    property ENABLED  : Extended read FENABLED   write FENABLED;
    property CREATEDATE: string read FCREATEDATE write FCREATEDATE;
    property CREATEUSER: string read FCREATEUSER write FCREATEUSER;
    property LATESTOPDATE: string read FLATESTOPDATE write FLATESTOPDATE;
    property LATESTOPUSER: string read FLATESTOPUSER write FLATESTOPUSER;
    property LASTVER  : string read FLASTVER   write FLASTVER;
    property SETYEAR  : Extended read FSETYEAR   write FSETYEAR;
    property RGCODE   : string read FRGCODE    write FRGCODE;
    property CCIDSTABLE: string read FCCIDSTABLE write FCCIDSTABLE;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AGLCOA:TGLCOA):TGLCOA;overload;        
    class procedure CopyIt(AGLCOA:TGLCOA;var Result:TGLCOA);overload;       
  end;

implementation

{ TGLCOA }
procedure TGLCOA.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('COA_ID').Value := COAID;
        ParamByName('COA_CODE').Value := COACODE;
        ParamByName('COA_NAME').Value := COANAME;
        ParamByName('COA_DESC').Value := COADESC;
        ParamByName('ENABLED').Value := ENABLED;
        ParamByName('CREATE_DATE').Value := CREATEDATE;
        ParamByName('CREATE_USER').Value := CREATEUSER;
        ParamByName('LATEST_OP_DATE').Value := LATESTOPDATE;
        ParamByName('LATEST_OP_USER').Value := LATESTOPUSER;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('RG_CODE').Value := RGCODE;
        ParamByName('CCIDS_TABLE').Value := CCIDSTABLE; 
      end;
      otEdit:
      begin
        ParamByName('COA_ID').Value := COAID;
        ParamByName('COA_CODE').Value := COACODE;
        ParamByName('COA_NAME').Value := COANAME;
        ParamByName('COA_DESC').Value := COADESC;
        ParamByName('ENABLED').Value := ENABLED;
        ParamByName('CREATE_DATE').Value := CREATEDATE;
        ParamByName('CREATE_USER').Value := CREATEUSER;
        ParamByName('LATEST_OP_DATE').Value := LATESTOPDATE;
        ParamByName('LATEST_OP_USER').Value := LATESTOPUSER;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('RG_CODE').Value := RGCODE;
        ParamByName('CCIDS_TABLE').Value := CCIDSTABLE; 
      end;  
      otDelt:
      begin
        ParamByName('COA_ID').Value := COAID;
 
      end;  
    end;
  end;
end;

function TGLCOA.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GL_COA',['COA_ID',COAID],AUniConnection);
end;

function TGLCOA.GetNextIdex: Integer;
begin

end;

function TGLCOA.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TGLCOA.GetStrDelete: string;
begin
  Result:='DELETE FROM GL_COA WHERE   COA_ID=:COA_ID';
end;

function TGLCOA.GetStrInsert: string;
begin
  Result:='INSERT INTO GL_COA'
         +'    ( COA_ID, COA_CODE, COA_NAME, COA_DESC, ENABLED, CREATE_DATE'
         +'    , CREATE_USER, LATEST_OP_DATE, LATEST_OP_USER, LAST_VER'
         +'    , SET_YEAR, RG_CODE, CCIDS_TABLE)'
         +'    VALUES'
         +'    (:COA_ID,:COA_CODE,:COA_NAME,:COA_DESC,:ENABLED,:CREATE_DATE'
         +'    ,:CREATE_USER,:LATEST_OP_DATE,:LATEST_OP_USER,:LAST_VER'
         +'    ,:SET_YEAR,:RG_CODE,:CCIDS_TABLE)';
end;

function TGLCOA.GetStrsIndex: string;
begin
  Result:=Format('%S',[COAID]);
end;

function TGLCOA.GetStrUpdate: string;
begin
  Result:='UPDATE  GL_COA SET'
         +'    COA_CODE=:COA_CODE,'
         +'    COA_NAME=:COA_NAME,'
         +'    COA_DESC=:COA_DESC,'
         +'    ENABLED=:ENABLED,'
         +'    CREATE_DATE=:CREATE_DATE,'
         +'    CREATE_USER=:CREATE_USER,'
         +'    LATEST_OP_DATE=:LATEST_OP_DATE,'
         +'    LATEST_OP_USER=:LATEST_OP_USER,'
         +'    LAST_VER=:LAST_VER,'
         +'    SET_YEAR=:SET_YEAR,'
         +'    RG_CODE=:RG_CODE,'
         +'    CCIDS_TABLE=:CCIDS_TABLE'
         +'    WHERE COA_ID=:COA_ID';
end;

constructor TGLCOA.Create;
begin

end;

destructor TGLCOA.Destroy;
begin

  inherited;
end;

class function TGLCOA.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TGLCOA.Create;

  with TGLCOA(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='COA_ID' then
      begin
        COAID    :=Field.AsString;
      end else
      if FieldName='COA_CODE' then
      begin
        COACODE  :=Field.AsString;
      end else
      if FieldName='COA_NAME' then
      begin
        COANAME  :=Field.AsString;
      end else
      if FieldName='COA_DESC' then
      begin
        COADESC  :=Field.AsString;
      end else
      if FieldName='ENABLED' then
      begin
        ENABLED  :=Field.AsFloat;
      end else
      if FieldName='CREATE_DATE' then
      begin
        CREATEDATE:=Field.AsString;
      end else
      if FieldName='CREATE_USER' then
      begin
        CREATEUSER:=Field.AsString;
      end else
      if FieldName='LATEST_OP_DATE' then
      begin
        LATESTOPDATE:=Field.AsString;
      end else
      if FieldName='LATEST_OP_USER' then
      begin
        LATESTOPUSER:=Field.AsString;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='RG_CODE' then
      begin
        RGCODE   :=Field.AsString;
      end else
      if FieldName='CCIDS_TABLE' then
      begin
        CCIDSTABLE:=Field.AsString;
      end;
    end
  end;  
end;

class procedure TGLCOA.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TGLCOA(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='COA_ID' then
      begin
        COAID    :=Field.AsString;
      end else
      if FieldName='COA_CODE' then
      begin
        COACODE  :=Field.AsString;
      end else
      if FieldName='COA_NAME' then
      begin
        COANAME  :=Field.AsString;
      end else
      if FieldName='COA_DESC' then
      begin
        COADESC  :=Field.AsString;
      end else
      if FieldName='ENABLED' then
      begin
        ENABLED  :=Field.AsFloat;
      end else
      if FieldName='CREATE_DATE' then
      begin
        CREATEDATE:=Field.AsString;
      end else
      if FieldName='CREATE_USER' then
      begin
        CREATEUSER:=Field.AsString;
      end else
      if FieldName='LATEST_OP_DATE' then
      begin
        LATESTOPDATE:=Field.AsString;
      end else
      if FieldName='LATEST_OP_USER' then
      begin
        LATESTOPUSER:=Field.AsString;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='RG_CODE' then
      begin
        RGCODE   :=Field.AsString;
      end else
      if FieldName='CCIDS_TABLE' then
      begin
        CCIDSTABLE:=Field.AsString;
      end;
    end
  end;  
end;

class function  TGLCOA.CopyIt(AGLCOA: TGLCOA): TGLCOA;
begin
  Result:=TGLCOA.Create;
  TGLCOA.CopyIt(AGLCOA,Result)
end;

class procedure TGLCOA.CopyIt(AGLCOA:TGLCOA;var Result:TGLCOA);
begin
  if Result=nil then Exit;
  Result.COAID    :=AGLCOA.COAID;
  Result.COACODE  :=AGLCOA.COACODE;
  Result.COANAME  :=AGLCOA.COANAME;
  Result.COADESC  :=AGLCOA.COADESC;
  Result.ENABLED  :=AGLCOA.ENABLED;
  Result.CREATEDATE:=AGLCOA.CREATEDATE;
  Result.CREATEUSER:=AGLCOA.CREATEUSER;
  Result.LATESTOPDATE:=AGLCOA.LATESTOPDATE;
  Result.LATESTOPUSER:=AGLCOA.LATESTOPUSER;
  Result.LASTVER  :=AGLCOA.LASTVER;
  Result.SETYEAR  :=AGLCOA.SETYEAR;
  Result.RGCODE   :=AGLCOA.RGCODE;
  Result.CCIDSTABLE:=AGLCOA.CCIDSTABLE;
end;

end.

